<%
// Inserts a link to the specified attribute of a particular HTML element.
//
// Parameters:
//  $0  The attribute to insert
//  $1  The element on which the attribute is used (optional)
//  $2  The text to display (between code)
//  $3  If set, do not put the text in <code></code>
//
// If the element isn't specified, the link is made to the Global Attributes
// page.

var lang = env.locale;
var url = "";

var globalAttrSlug = mdn.localString({
    "en-US": "Global_attributes",
    "fr"   : "Attributs_universels"
});

const attrLC = $0.toLowerCase();

var text = ($2 && ($2!=undefined)) ? $2 : attrLC;

let basePath;
if ($1) {
    basePath = '/' + lang + '/docs/Web/HTML/Element/';
    url = basePath + $1;
} else {
    url = '/' + lang + '/docs/Web/HTML/' + globalAttrSlug;
}

if (!$3) {
  text = `<code>${text}</code>`;
}

const result = web.smartLink(`${url}#attr-${attrLC}`, null, text, $1, basePath);

%>
<%- result %>
